package com.chaihu.generator.backend;

import com.chaihu.generator.util.FileUtilBase;

public class GeneratorServiceDaoMapper extends BaseGenerator {


    /**
     * 生成代码
     *
     * @param data
     */
    public void generator(Data data) throws Exception {
        StringBuffer sb = readFile("backendTemplate/ServiceDaoMapper.txt");
        String fileContext = sb.toString();
        fileContext = fileContext
                .replace("@@moduleName@@", data.getModuleName())
                .replace("Order", toUpperCaseFirstOne(data.getName()))
                .replace("描述", data.getDesc());

        String writePath = BaseGenerator.getClassPath()
                + "out/backend/mapper/" + data.getModuleName() + "/" + toUpperCaseFirstOne(data.getName()) + "ServiceDaoMapper.xml";

        writeFile(writePath, fileContext);
        //复制生成的文件到对应分区目录下
        if (data.isAutoMove()) {
            String distPath = "chaihu-db\\src\\main\\resources\\mapper\\" + data.getModuleName() + "\\" + "/" + toUpperCaseFirstOne(data.getName()) + "ServiceDaoMapper.xml";
//            System.out.println(distPath);
            FileUtilBase.copyfile(writePath, distPath);
        }
    }
}
